<template>
    <view class="container">
        <view class="headName">{{ headName }}</view>
        <view class="form">
            <view class="form-item">
                <view class="label-title">收货人</view>
                <view class="form-item-value">
                    <input
                        @input="__e"
                        :data-event-opts="[['input', [['__set_model', ['$0', 'consignee', '$event', []], ['form']]]]]"
                        placeholder="请填写收货人姓名"
                        placeholderClass="placeholder"
                        type="text"
                        :value="form.consignee"
                    />
                </view>
            </view>
            <view class="form-item">
                <view class="label-title">手机号码</view>
                <view class="form-item-value">
                    <input
                        @input="__e"
                        :data-event-opts="[['input', [['__set_model', ['$0', 'phone', '$event', []], ['form']]]]]"
                        placeholder="请填写收货人手机号"
                        placeholderClass="placeholder"
                        type="text"
                        :value="form.phone"
                    />
                </view>
            </view>
            <view class="form-item">
                <view class="label-title">所在地区</view>
                <view class="form-item-value">
                    <area-select
                        @__l="__l($event, { eventOpts: [['^change', [['areaChange']]]] })"
                        @change="__e($event, { eventOpts: [['^change', [['areaChange']]]] })"
                        :data-event-opts="[['^change', [['areaChange']]]]"
                        :value="defaultAddressValue"
                        vueId="7d007718-1"
                    ></area-select>
                </view>
            </view>
            <view class="form-item">
                <view class="label-title">详细地址</view>
                <view class="form-item-value">
                    <textarea
                        @input="__e"
                        :data-event-opts="[['input', [['__set_model', ['$0', 'address', '$event', []], ['form']]]]]"
                        placeholder="街道、楼牌号等"
                        placeholderClass="text-placeholder"
                        :value="form.address"
                    ></textarea>
                </view>
            </view>
            <view class="form-item">
                <view class="label-title">标签</view>
                <view class="form-item-value">
                    <view class="labels">
                        <view
                            @tap="__e"
                            :class="['label-item', form.tag === item ? 'active' : '']"
                            :data-event-opts="[['tap', [['handleClick', ['$event']]]]]"
                            :data-tag="item"
                            v-for="(item, __i0__) in tags"
                            :key="__i0__"
                        >
                            {{ '' + item + '' }}
                        </view>
                    </view>
                </view>
            </view>
            <view class="form-item">
                <view class="label-title" style="width: 200rpx">设为默认地址</view>
                <view class="form-item-value">
                    <view class="switch">
                        <switch
                            @change="__e"
                            :checked="form.is_default ? true : false"
                            color="#9DF9FC"
                            :data-event-opts="[['change', [['switchChange', ['$event']]]]]"
                            style="transform: scale(0.8)"
                        ></switch>
                    </view>
                </view>
            </view>
        </view>
        <view class="footer">
            <view @tap="__e" class="footer-button" :data-event-opts="[['tap', [['handleSubmit', ['$event']]]]]" hoverClass="hover">
                <text></text>
            </view>
        </view>
    </view>
</template>

<script>
import areaSelect from '@/components/AreaSelect/AreaSelect';
import tabBar from '@/components/TabBar/tabBar';
(global.webpackJsonp = global.webpackJsonp || []).push([
    ['pages/setAddress/index'],
    {
        '0524': function (t, e, i) {},
        '071e': function (t, e, i) {
            'use strict';

            (function (t, e) {
                var n = i('4ea4');
                i('18ba');
                n(i('66fd'));
                var r = n(i('f410'));
                t.__webpack_require_UNI_MP_PLUGIN__ = i;
                e(r.default);
            }.call(this, i('bc2e').default, i('543d').createPage));
        },
        '0870': function (t, e, i) {
            'use strict';

            i.d(e, 'b', function () {
                return r;
            });
            i.d(e, 'c', function () {
                return o;
            });
            i.d(e, 'a', function () {
                return n;
            });
            var n = {
                AreaSelect: function () {
                    return i.e('components/AreaSelect/AreaSelect').then(i.bind(null, '1aef'));
                }
            };
            var r = function () {
                this.$createElement;
                this._self._c;
            };
            var o = [];
        },
        '1ef0': function (t, e, i) {
            'use strict';

            (function (t) {
                Object.defineProperty(e, '__esModule', {
                    value: true
                });
                e.default = void 0;
                var n = i('a7b1');
                var r = {
                    data: function () {
                        return {
                            headName: null,
                            tags: ['家', '公司', '学校'],
                            uuid: '',
                            form: {
                                consignee: '',
                                phone: '',
                                province: '',
                                city: '',
                                district: '',
                                address: '',
                                tag: '',
                                is_default: 0
                            }
                        };
                    },
                    computed: {
                        defaultValue: function () {
                            return [this.form.province, this.form.city, this.form.district];
                        },
                        defaultAddressValue: function () {
                            return this.form.province ? [this.form.province, this.form.city, this.form.district] : null;
                        },
                        pickerSelected: function () {
                            return this.form.province ? this.form.province + '-' + this.form.city + '-' + this.form.district : '';
                        }
                    },
                    onLoad: function (e) {
                        t.setNavigationBarTitle({
                            title: e.uuid ? '编辑收货地址' : '新建收货地址'
                        });
                        console.log(e.uuid, 'qq');
                        null == e.uuid ? (this.headName = '新建收货地址') : (this.headName = '编辑收货地址');
                        if (e.uuid) {
                            this.uuid = e.uuid;
                            t.setNavigationBarTitle({
                                title: '编辑收货地址'
                            });
                            var i = this.$navigator.getParameters() || {};
                            this.form = {
                                consignee: i.consignee,
                                phone: i.phone,
                                province: i.province,
                                city: i.city,
                                district: i.district,
                                address: i.address,
                                tag: i.tag,
                                is_default: i.is_default
                            };
                        }
                    },
                    methods: {
                        handleClick: function (t) {
                            this.form.tag = t.currentTarget.dataset.tag;
                        },
                        switchChange: function (t) {
                            this.form.is_default = t ? 1 : 0;
                        },
                        change: function (t) {
                            var e = t.detail.value;
                            this.form.province = e[0];
                            this.form.city = e[1];
                            this.form.district = e[2];
                        },
                        areaChange: function (t) {
                            var e = t.labelArr;
                            this.form.province = e[0];
                            this.form.city = e[1];
                            this.form.district = e[2];
                        },
                        handleSubmit: function () {
                            var e = this.form;
                            e.consignee
                                ? /^1\d{10}$/.test(e.phone)
                                    ? this.pickerSelected
                                        ? e.address
                                            ? (t.showLoading({
                                                  title: '加载中'
                                              }),
                                              this.uuid
                                                  ? (0, n.updateAddress)(e, this.uuid).then(function (e) {
                                                        t.navigateBack({
                                                            delta: 1
                                                        });
                                                    })
                                                  : (0, n.createAddress)(e).then(function (e) {
                                                        t.navigateBack({
                                                            delta: 1
                                                        });
                                                    }))
                                            : t.showToast({
                                                  title: '请填写详细地址',
                                                  icon: 'none'
                                              })
                                        : t.showToast({
                                              title: '请选择所在地区',
                                              icon: 'none'
                                          })
                                    : t.showToast({
                                          title: '请填写正确的手机号',
                                          icon: 'none'
                                      })
                                : t.showToast({
                                      title: '请填写收货人姓名',
                                      icon: 'none'
                                  });
                        }
                    }
                };
                e.default = r;
            }.call(this, i('543d').default));
        },
        '3ef3': function (t, e, i) {
            'use strict';

            i.r(e);
            var n = i('1ef0');
            var r = i.n(n);
            for (var o in n) {
                if (['default'].indexOf(o) < 0) {
                    (function (t) {
                        i.d(e, t, function () {
                            return n[t];
                        });
                    })(o);
                }
            }
            e.default = r.a;
        },
        f054: function (t, e, i) {
            'use strict';

            var n = i('0524');
            i.n(n).a;
        },
        f410: function (t, e, i) {
            'use strict';

            i.r(e);
            var n = i('0870');
            var r = i('3ef3');
            for (var o in r) {
                if (['default'].indexOf(o) < 0) {
                    (function (t) {
                        i.d(e, t, function () {
                            return r[t];
                        });
                    })(o);
                }
            }
            i('f054');
            var a = i('f0c5');
            var c = Object(a.a)(r.default, n.b, n.c, false, null, null, null, false, n.a, void 0);
            e.default = c.exports;
        }
    },
    [['071e', 'common/runtime', 'common/vendor']]
]);
</script>
<style>
@import './index.css';
</style>
